function [ ] = plotAbatementAggregate( obj, filename, titleString )
% plotAbatementAggregate Plot aggregate emissions as a function of
%   abatement expenditure
%
% INPUTS:
%   obj : etsModel object

%% Formatting options
textProp = {'fontsize'    , 14, ...
            'FontName'    , 'Times New Roman'};
labProp  = {'fontsize'    , 14, ...
            'FontName'    , textProp{4}};

%% Preparation of data for plot

% Range of prices
obj.period = 1;
p_star = obj.solveMarketOne;

steps = 100;
p_min = round(0.10*p_star,5);
p_max = round(2*p_star,5);
p_inc = (p_max - p_min)/(steps-1);
Pt    = [ p_min:p_inc:p_max ]';

% Calculate emissions at each price
Et    = nan(size(Pt));

fprintf(1,'Solving for emissions at different prices . . . \n');
for t = 1:length(Et)
    [  Et(t) ] = obj.solvePlantEmissions( Pt(t) );
    if mod(t,10) == 0
        fprintf(1,'  Price = %7.2f, Emissions = %7.2f\n',Pt(t),Et(t));
    end
end


%% Plot residual demand, own supply and market clearing
f0 = figure;

h1 = plot(Et,Pt,'k-','LineWidth',2);
hold on;

xlabel('Emissions (kg)',textProp{:},'Interpreter','latex');
ylabel('Price (INR/kg)',textProp{:},'Interpreter','latex');

title(titleString,textProp{:},'Interpreter','latex');

% Figure formatting
set(gcf, 'Color'       , 'w' );
set(gca, labProp{:}, ...
         'Box'         , 'off'              , ...
         'LineWidth'   , 1.5                , ...
         'PlotBoxAspectRatio', [1 0.75 0.75]);  

% % Vertical line at zero
% h3 = plot([0,0],[pmin,pmax],'k-','LineWidth',1.5);


% Reset axis limits
xl = xlim;
xmax = xl(2);
xlim([ 0 xmax ]);


%% Legend 
% legend([h1(1) h1(2) h2(1)],...
%         'Residual demand',...
%         'Residual demand (smoothed)',...
%         'Own supply',...
%         'Location','southoutside',...
%         'Orientation','vertical',...
%         'FontName','Times New Roman',...
%         'fontsize',18);
% legend boxoff;
hold off;

%% Export figure

% Crop whitespace 
fig = gcf;
fig.PaperPositionMode = 'auto';
fig_pos = fig.PaperPosition;
fig.PaperSize = [fig_pos(3) fig_pos(4)];

ax = gca;
outerpos = ax.OuterPosition;
ti = ax.TightInset;
left = outerpos(1) + ti(1);
bottom = outerpos(2) + ti(2);
ax_width = outerpos(3) - ti(1) - ti(3);
ax_height = outerpos(4) - ti(2) - ti(4);
ax.Position = [left bottom ax_width ax_height];

fprintf(1,'Writing %s to file ...\n',filename);
print(f0,'-dpdf','-painters','-noui','-r600',filename);
fprintf(1,' complete.\n');

end